<template>
	<view class="homeCategory">
		<view class="categoryItem" v-for="item in categoryData" :key="item._id" @click="toCategory">
			<image :src="item.image_src" mode="widthFix"></image>
			<view>{{item.name}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "homeCategory",
		data() {
			return {
				categoryData: [],
			};
		},
		methods: {
			async getCatitems() {
				const data = await this.$api.home.getCatitems();
				if (data.meta.status == 200) {
					this.categoryData = data.message;
				}
			},
			toCategory() {
				uni.navigateTo({
					url: '/pages/category/category'
				})
			}
		},
		created() {
			this.getCatitems();
		}
	}
</script>

<style scoped lang="scss">
	.homeCategory {
		position: relative;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		z-index: 999;

		.categoryItem {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			width: 128rpx;
			height: 128rpx;

			image {
				width: 64rpx;
			}
		}
	}
</style>
